package com.dd.controller;


import com.dd.pojo.Shop;
import com.dd.pojo.Yuyue;
import com.dd.service.ShopService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    ShopService shopService;

    @RequestMapping("/finduname")
    public String finduname(String uname) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        List<Shop> list = shopService.finduname(uname);
        String str = mapper.writeValueAsString(list);
        String jso = "{\"code\":0,\"msg\":\"\",\"count\":" + 25 + ",\"data\":" + str + "}";
        return jso;
    }

    @RequestMapping("/addshop")
    public String addshop(Shop shop){
        shopService.addshop(shop);
        return "1";
    }

    @RequestMapping("/deleteshop")
    public String deleteshop(int id){
        shopService.deleteshop(id);
        return "1";
    }
}
